package com.wn.cainiao

import com.wn.cainiao.databinding.ActivityMainBinding
import com.wn.cainiao.utils.FragmentProvider
import com.wn.cainiao.widget.MainViewPagerAdapter
import com.wn.common.base.BaseActivity
import com.wn.common.ktx.immediateStatusBar
import com.wn.common.widget.BottomNavVP2Mediator
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

/**
 * @Author: wn
 * @Date: 2023/3/27 15:55
 * @Description: App主工程的入口界面
 */
@AndroidEntryPoint
class MainActivity : BaseActivity<ActivityMainBinding>() {

  @Inject
  lateinit var fragmentProvider: FragmentProvider

  override fun getLayoutRes() = R.layout.activity_main

  override fun initView() {
    super.initView()
    // 初始化控件
    mBinding.apply {
      // viewpager2数据适配器 初始化
      vp2Main.adapter = MainViewPagerAdapter(this@MainActivity, fragmentProvider.fragments)
      // 将bnv和vp2事件绑定
      BottomNavVP2Mediator(navView, vp2Main, lifecycle) { _, v2 ->
        // viewpager不需要滑动
        v2.isUserInputEnabled = false
      }.attach()
    }
    immediateStatusBar()
  }

/*  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    binding = ActivityMainBinding.inflate(layoutInflater)
    setContentView(binding.root)

    val navView: BottomNavigationView = binding.navView
    // xml 修改 fragment
    //1、先拿NavHostFragment
    val navHostFragment =
      supportFragmentManager.findFragmentById(R.id.nav_host_fragment_activity_main) as NavHostFragment
    //2、再拿NavController
    val navController = navHostFragment.navController
    // val navController = findNavController(R.id.nav_host_fragment_activity_main)
    val appBarConfiguration = AppBarConfiguration(
      setOf(
        R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications
      )
    )
    setupActionBarWithNavController(navController, appBarConfiguration)
    navView.setupWithNavController(navController)
  }*/
}